package sg20.task2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class TaskTwoCourseMapper extends Mapper<LongWritable, Text, LongWritable, Text> {
    private int universityLineCnt = 0;


    @Override
    protected void setup(Mapper<LongWritable, Text, LongWritable, Text>.Context context) throws IOException, InterruptedException {
        super.setup(context);
        this.universityLineCnt = Integer.parseInt(context.getConfiguration().get("universityLineCnt"));
    }
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, LongWritable, Text>.Context context) throws IOException, InterruptedException {
        String[] vals = value.toString().split("\\|");
        for (int idx = 0; idx < universityLineCnt; idx++) {
            context.write(new LongWritable(idx), new Text(vals[0] + "|" + vals[1] + "|" + vals[2] + "|" + vals[3] + "|"));
        }


    }
}
